package com.rbac.api.mybatis.sqlProvider;


import com.rbac.api.mybatis.entityCus.CusAdRoleLinkedEntity;


import java.text.MessageFormat;
import java.util.List;
import java.util.Map;

public class AdminRolesUsersSqlProvider {


    private final String errorDataDefaultSQL = "select count(1) from admin_roles_users where id = '0' LIMIT 1";
    ///组装校验合格的写入数据SQL
    private static final MessageFormat mf = new MessageFormat("(#'{'list[{0}].roleNo,jdbcType=VARCHAR},#'{'list[{0}].linkedNo,jdbcType=VARCHAR})");
    public String insertManyRolesUsersDataSelective(Map map) {
        //获取参数
        List<CusAdRoleLinkedEntity> record_list = (List<CusAdRoleLinkedEntity>) map.get("list");
        //如果参数为空
        if(record_list.size() == 0){
            return errorDataDefaultSQL;
        }
        //拼接批量写入语句
        StringBuilder sb = new StringBuilder();
        sb.append("INSERT INTO `admin_roles_users` ");
        sb.append("(`role_no`, `user_no`) ");
        sb.append("VALUES ");
        for (int i = 0; i < record_list.size(); i++) {
            sb.append(mf.format(new Object[]{i}));
            if (i < record_list.size() - 1) {
                sb.append(",");
            }
        }
        String sql = sb.toString().trim();


        return sql;
    }








}